{extend name="layout/iframe" /}

{block name="content"}
<div class="layui-card-body layui-layout-admin" style="padding: 15px;">
    <form class="layui-form" action="" lay-filter="component-form-group">
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="required">*</span>菜谱名称</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" id="name" name="name" value="{$info.name}" data-name="{$info.name}" maxlength="40" lay-verify="name" placeholder="" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item layui-form-text layui-col-xs5">
            <label class="layui-form-label"><span class="required">*</span>封面</label>
            <div id="upload-image">
                <div class="layui-upload-list thumbBox mag0 magt3" id="upload-btn" data-multi="false">
                    <input type="hidden" class="layui-input" name="img_url" value="{$info.img_url}" lay-verify="img_url">
                    <img class="layui-upload-img thumbImg" src="{$info.img_url}">
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="required">*</span>菜谱简介</label>
            <div class="layui-input-block">
                <textarea name="introduction" lay-verify="required" placeholder="" class="layui-textarea">{$info.introduction}</textarea>
            </div>
        </div>
        <!-- 食材 -->
        <div class="ingredients-div">
            <div class="ingredients-group">
                {foreach name="info.ingredients" item="ingredient" key="ingkey"}
                    <div class="layui-form-item layui-form-text ingredient-group">
                        <div class="layui-inline">
                            <label class="layui-form-label"><span class="required">*</span>食材名称</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input ingredient_name" name="ingredient_name[{$ingkey}]" value="{$ingredient.name}" maxlength="40" placeholder="" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 70px;"><span class="required">*</span>用量</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input ingredient_num" name="ingredient_num[{$ingkey}]" value="{$ingredient.num}" maxlength="15" placeholder="" autocomplete="off">
                            </div>
                        </div>
                        {if condition="($ingkey > 0)"}
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <button type="button" class="layui-btn layui-btn-danger delIngredient-btn"><i class="layui-icon layui-icon-delete"></i></button>
                                </div>
                            </div>
                        {/if}
                    </div>
                {/foreach}
            </div>

            <div class="layui-form-item layui-form-text">
                <div class="layui-inline">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-inline">
                        <button type="button" class="layui-btn layui-btn-normal addIngredient-btn"><i class="layui-icon"></i>添加食材</button>
                    </div>
                </div>
            </div>
        </div>

        <div class="cookbook_step-div">
            <div class="cookbook_step-group">
                {foreach name="info.cookbookStep" item="step" key="stepkey"}
                    <div class="layui-form-item layui-form-text step-group">
                        <div class="layui-col-xs5">
                            <label class="layui-form-label"><span class="required">*</span>步骤图</label>
                            <div id="upload-image-{$stepkey}">
                                <div class="layui-upload-list thumbBox mag0 magt3" id="upload-btn-{$stepkey}" data-multi="false">
                                    <input type="hidden" class="layui-input step_img_url" name="step_img_url[{$stepkey}]" value="{$step.img_url}">
                                    <img class="layui-upload-img thumbImg" src="{$step.img_url}">
                                </div>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 70px;"><span class="required">*</span>步骤说明</label>
                            <div class="layui-input-inline">
                                <textarea class="layui-textarea content" name="content[{$stepkey}]" placeholder="">{$step.content}</textarea>
                            </div>
                        </div>
                        {if condition="($stepkey > 0)"}
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <button type="button" class="layui-btn layui-btn-danger delStep-btn"><i class="layui-icon layui-icon-delete"></i></button>
                                </div>
                            </div>
                        {/if}
                    </div>
                {/foreach}
            </div>

            <div class="layui-form-item layui-form-text">
                <div class="layui-inline">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-inline">
                        <button type="button" class="layui-btn layui-btn-normal addStep-btn"><i class="layui-icon"></i>添加步骤</button>
                    </div>
                </div>
            </div>
        </div>

        <input type="hidden" name="id" value="{$info.id}">

        <div class="layui-form-item layui-row layui-col-xs12">
            <div class="layui-input-block">
                <div class="layui-footer">
                    <button type="button" class="layui-btn layui-btn-primary close-btn">取消</button>
                    <button type="button" class="layui-btn" lay-submit="" lay-filter="laySave">保存 <i class="layui-icon">&#xe609;</i></button>
                </div>
            </div>
        </div>
    </form>
</div>

<input type="hidden" class="save_url" value="{:url('admin/cookbook/savepost')}">
{/block}

{block name="pagescript"}
<script src="__STATIC__/admin/js/qiniu/plupload.full.min.js" type="text/javascript"></script>
<script src="__STATIC__/admin/js/qiniu/qiniu.js" type="text/javascript"></script>
<script src="__STATIC__/admin/js/qiniu/qiniuConfig.js" type="text/javascript"></script>

<script src="__STATIC__/admin/pages/js/uploadfile.js" type="text/javascript"></script>
<script src="__STATIC__/admin/pages/js/cookbook.js" type="text/javascript"></script>
{/block}